package leetcode.offer;

/**
 * ClassName: SearchI
 * Description: leetcode-剑指offer 53 - I 在排序数组中查找数字 I
 * date: 2021-10-31 22:35
 *
 * @author liyifan
 */
public class SearchI {
    public int search(int[] nums, int target) {
        // todo 二分左右边界
        int left =0,right = nums.length-1;
        int count = 0;
        while(left<right){
            int mid = (left+right)/2;
            if(nums[mid]>=target)
                right=mid;
            if(nums[mid]<target)
                left = mid+1;
        }
        while(left<nums.length&&nums[left++]==target)
            count++;
        return count;
    }
}
